﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage
{
    public partial class modifyArticle : System.Web.UI.Page
    {
        ArticleBLL abll = new ArticleBLL();
        ArtTypeBLL atbll = new ArtTypeBLL();
        public int page = 1;
        public int pid;
        Com.CMS263.PO.ArtType type = null;
      
        protected void Page_Load(object sender, EventArgs e)
        {
            pid = int.Parse(Request["pid"]);
            type = atbll.GetArtTypeById(pid);
            page = string.IsNullOrEmpty(Request["page"]) ? 1 : int.Parse(Request["page"]);
            this.lbTypeName.Text = type.typeName;
            this.hdfTypeId.Value = pid.ToString();
            if (!this.IsPostBack)
            {
                //根据父类编号取得单条信息以修改
                Article art = abll.GetArticleByPid(pid);
                if (art == null)
                {

                    Response.Redirect("AddArticle.aspx?pid=" + pid);
                }
                else
                {
                    this.BindArticle(art);
                }
                this.txtAddDate.Text = DateTime.Now.ToString();
            }


        }

        private void BindArticle(Article art)
        {
            if (art.title.IndexOf("<b>") > 0)
            {
                this.chkStrong.Checked = true;
            }
            if (art.title.IndexOf("color:red")>0)
            {
                this.chkRed.Checked = true;
            }
           
            this.txtAddDate.Text = art.addDate.ToString();
            this.txtRemark.Text = art.remark;
            this.txtTitle.Text = art.title.Replace("<span style='color:red'>","").Replace("</span>","").Replace("<b>","").Replace("</b>","");
            this.con.Value = art.content;
            this.hdfTypeId.Value = pid.ToString();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Article article = abll.GetArticleByPid(int.Parse(this.hdfTypeId.Value));
            string title = this.txtTitle.Text;
            string remark = this.txtRemark.Text;
            string con = this.con.Value;
            string addDate = this.txtAddDate.Text;

            if (chkStrong.Checked)
            {
                title = "<b>" + title + "</b>";

            }
            if (this.chkRed.Checked)
            {
                title = "<span style='color:red'>" + title + "</span>";
            }


           

            article.title = title;
           
            article.remark = remark;

            article.addDate = DateTime.Parse(addDate);
          
            article.typeID = int.Parse(this.hdfTypeId.Value);
            article.content = con;
            abll.ModifyArt(article);
         
            StringUtil.Alert("修改成功", "modifyArticle.aspx?pid=" + this.hdfTypeId.Value);
       
          
            
        }
    }
}
